package cn.com.huzo.repository.manufacture.impl;

import cn.com.huzo.model.entities.manufacture.CommissionProcessingContractLinesEntity;
import cn.com.huzo.repository.manufacture.CommissionProcessingContractLinesRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 加工承揽合同-合同明细数据访问对象。
 *
 * @author 吴旭
 */
@Repository("CommissionProcessingContractLinesRepository")
public class CommissionProcessingContractLinesRepositoryImpl extends GenericRepositoryImpl<CommissionProcessingContractLinesEntity, String>
        implements CommissionProcessingContractLinesRepository {

    private final String namespace = "cn.com.huzo.repository.manufacture.CommissionProcessingContractLinesRepository";

    /**
     * 构造函数,设置the entity to SampleLinesRepositoryImpl.class.
     */
    public CommissionProcessingContractLinesRepositoryImpl() {
        super(CommissionProcessingContractLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<CommissionProcessingContractLinesEntity> fetchByHeaderKey(Long headerKey) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderKey"), headerKey);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<CommissionProcessingContractLinesEntity> fetchLinesForCmtStatistics(List<CommissionProcessingContractLinesEntity> itemList) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchLinesForCmtStatistics"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insert(Long headerId, Long createdBy, Long updatedBy) {
        Map<String, Object> params = new HashMap<>();
        params.put("HeaderId", headerId);
        params.put("CreatedBy", createdBy);
        params.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), params);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateForSyncQuantity(Long headerId, Long updatedBy) {
        Map<String, Object> params = new HashMap<>();
        params.put("HeaderId", headerId);
        params.put("UpdatedBy", updatedBy);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateForSyncQuantity"), params);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<CommissionProcessingContractLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer deleteForSyncLinesMo(Long headerKey) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "deleteForSyncLinesMo"), headerKey);
    }
}
